import requests
import json

def has_work(server):  # 判断是否有待配送的订单(已测试)
    response = requests.get(server + '/task')
    res_dic = json.loads(response.text)

    if res_dic['data']  == 0:
        return False
    else:
        return True

def get_work(server, car_pt, car_id, temp, hum):  # 接受订单(已测试)
    data = {
        "car_pt": car_pt,
        "car_id": car_id,
        "i_temp": temp,
        "i_hum": hum
    }
    response = requests.post(server + '/task', json=data)
    res_dic = json.loads(response.text)
    if res_dic['code']  == 1:
        oid = res_dic['data']['oid']
        paths = res_dic['data']['paths']
        return 1, oid, paths
    elif res_dic['code'] == 0:
        return 0, None, None
    else:
        return -1, None, None
    


